/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.security.MessageDigest;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author DEVAIR
 */
public abstract class IntranetUtil {

    public static Date dataSimples(String dataString) {
        Date data = null;
        DateFormat df = DateFormat.getDateInstance();

        try {
            data = df.parse(dataString);
        } catch (ParseException ex) {
            Logger.getLogger(IntranetUtil.class.getName()).log(Level.SEVERE, null, ex);
        }

        return data;
    }
     
    public static Date dataTempo(String dataString) {
        Date data = null;
        DateFormat df = DateFormat.getDateTimeInstance();

        try {
            data = df.parse(dataString);
        } catch (ParseException ex) {
            Logger.getLogger(IntranetUtil.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return data;
    }

    public static String criptografa(String senha) {
        String senhaCriptografada = null;


        try {
            MessageDigest algorithm;
            algorithm = MessageDigest.getInstance("SHA-256");
            byte messageDigest[] = algorithm.digest(senha.getBytes("UTF-8"));

            StringBuilder hexString = new StringBuilder();
            for (byte b : messageDigest) {
                hexString.append(String.format("%02X", 0xFF & b));
            }
            senhaCriptografada = hexString.toString();

        } catch (Exception ex) {
            Logger.getLogger(IntranetUtil.class.getName()).log(Level.SEVERE, null, ex);
        }

        return senhaCriptografada;

    }
}
